package StudyCode.summary.Basic.mystring;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class StringGetIP {

	public static void main(String[] args) {
		String http = "http://192.168.0.1:888/asdsdsds/dsdffdf";
		String http1 = "http:\\\\192.168.0.1:888/asdsdsds/dsdffdf";
		System.out.println(getIp(http));
		System.out.println(getIp(http1));
	}

	private static String getIp(String s) {
		Pattern pattern = Pattern.compile("^((http://)?\\S+):");
		Matcher matcher = pattern.matcher(s);
		if (matcher.find()) {
			return matcher.group(1);
		}
		return null;
	}
}
